import { List } from 'antd-mobile'
import { useParams } from 'react-router-dom'
import { addSearchHistory } from '../../../store/slice/ticketSlice'
import { useDispatch } from 'react-redux'

function SearchList(props) {
  const params = useParams()
  const dispatch = useDispatch()

  return (
    <div>
      <List>
        {props.list.map((item, i) => (
          <List.Item
            key={i}
            // 把点击的城市，存入仓库中
            onClick={() => {
              // 把点击的城市，存储到全局搜索历史中
              dispatch(addSearchHistory(item.name))
              // 跳转回首页
              props.saveCity(params.type, item.name)
            }}
          >
            {item.name}
          </List.Item>
        ))}
      </List>
    </div>
  )
}

export default SearchList
